"Utility functions for file and string manipulation" import string def lines_from_file(path): """Return a list of strings, one for each line in a file.""" with open(path, 'r') as f: return [line.strip() for line in f.readlines()] punctuation_remover = str.maketrans('', '', string.punctuation) def remove_punctuation(s): """Return a string with the same contents as s, but with punctuation removed. >>> remove_punctuation("It's a lovely day, don't you think?") 'Its a lovely day dont you think' """ return s.strip().translate(punctuation_remover) def lower(s): """Return a lowercased version of s.""" return s.lower() def split(s): """Return a list of words contained in s, which are sequences of characters separated by whitespace (spaces, tabs, etc.). >>> split("It's a lovely day, don't you think?") ["It's", 'a', 'lovely', 'day,', "don't", 'you', 'think?'] """ return s.split()